import actionTypes from '../actions/actionTypes';
const initState = {
  loading: false,
  list: [
    {
      id: 1,
      title: 'dsfegdbg',
      description:
        'efbrgnbtbhetgqergadfvegegdvefrtqeafwgtrrbeEWEFWGQETBET DFVETBESFEGQEGSDDFAEBGEEERGETHEQRGFHRTGGQEHSGEQRGEQR',
      hasRead: true,
      avatar: 'https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png'
    },
    {
      id: 2,
      title: 'dsfegdbg',
      description:
        'efbrgnbtbhetgqergadfvegegdvefrtqeafwgtrrbeEWEFWGQETBET DFVETBESFEGQEGSDDFAEBGEEERGETHEQRGFHRTGGQEHSGEQRGEQR',
      hasRead: false,
      avatar: 'https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png'
    },
    {
      id: 3,
      title: 'dsfegdbg',
      description:
        'efbrgnbtbhetgqergadfvegegdvefrtqeafwgtrrbeEWEFWGQETBET DFVETBESFEGQEGSDDFAEBGEEERGETHEQRGFHRTGGQEHSGEQRGEQR',
      hasRead: false,
      avatar: 'https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png'
    },
    {
      id: 4,
      title: 'dsfegdbg',
      description:
        'efbrgnbtbhetgqergadfvegegdvefrtqeafwgtrrbeEWEFWGQETBET DFVETBESFEGQEGSDDFAEBGEEERGETHEQRGFHRTGGQEHSGEQRGEQR',
      hasRead: true,
      avatar: 'https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png'
    }
  ]
};
export default (state = initState, action) => {
  switch (action.type) {
    case actionTypes.MARK_NOTIFICATIONS_AS_READ_BY_ID:
      const list = state.list.map(item => {
        return {
          ...item,
          hasRead: item.id === action.payLoad.id ? !item.hasRead : item.hasRead
        };
      });
      return {
        ...state,
        list
      };
    case actionTypes.MARK_ALL_NOTIFICATIONS_AS_READ:
      return {
        ...state,
        list: state.list.map(item => {
          return {
            ...item,
            hasRead: true
          };
        })
      };
    case actionTypes.START_NOTIFICATIONS_LOADING:
      return {
        ...state,
        loading: true
      };
    case actionTypes.FINISH_NOTIFICATIONS_LOADING:
      return {
        ...state,
        loading: false
      };
    case actionTypes.FINISH_GET_ALL_NOTOFICATIONS:
      return {
        ...state,
        list: action.payLoad.list
      };
    default:
      return state;
  }
};
